﻿@using CuongHanh
@model Tuple<int, int?>
<script type="text/javascript">

    function getImage(value, record) {
        var url = '@Url.Content(AppUtil.GEM_IMAGE_PATH)';
        return "<img style='height:40px;' alt='no image' src='" + url + (value ? value : "no-image.jpg") + "'/>";
    }

</script>
@(Html.X()
          .Panel()
          .Width(795)
          .Height(400)
          .Layout(LayoutType.Border)
          .Items(view =>
                 {
                     Toolbar topMenu = new Toolbar
                                       {
                                               Region = Region.North
                                       };
                     view.Add(topMenu);
                     topMenu.Add(new ToolbarFill());
                     topMenu.Add(Html.X()
                             .Button()
                             .Text("Thêm mới")
                             .Icon(Icon.Add)
                             .DirectEvents(de =>
                                           {
                                               de.Click.Url = Url.Action("ShowAddParentMaterial");
                                               de.Click.ExtraParams.Add(new Parameter("containerId",
                                                       "wdModifyChild"));
                                               de.Click.ExtraParams.Add(new Parameter("styleId",
                                                       Model.Item1 + ""));
                                               de.Click.ExtraParams.Add(new Parameter("parentStyleId",
                                                       (Model.Item2 ?? 0) + ""));
                                           })
                             );

                     view.Add(Html.X()
                             .GridPanel()
                             .ForceFit(true)
                             .ID("gvChildData")
                             .View(Html.X()
                                     .GridView()
                                     .EnableTextSelection(true)
                             )
                             .Region(Region.Center)
                             .ColumnModel(column =>
                                          {
                                              column.Add(Html.X()
                                                      .Column()
                                                       .MinWidth(55)
                                                     .MaxWidth(55)
                                                      .DataIndex("Image")
                                                      .Renderer("getImage")
                                                      );
                                              column.Add(Html.X()
                                                      .Column()
                                                      .DataIndex("ParentStyleName")
                                                      .Text("Mẫu (Cha)")
                                                      );
                                              column.Add(Html.X()
                                                      .Column()
                                                      .DataIndex("ParentMaterialName")
                                                      .Text("Chất liệu (Cha)")
                                                      );
                                              column.Add(Html.X()
                                                      .NumberColumn()
                                                      .DataIndex("Price")
                                                      .Text("Giá")
                                                      .Align(Alignment.Right)
                                                      .Format(AppUtil.NUMBER_FORMAT)
                                                      );

                                              column.Add(Html.X()
                                                      .CommandColumn()
                                                      .MinWidth(65)
                                                      .MaxWidth(65)
                                                      .Commands(v =>
                                                              v.Add(new GridCommand
                                                                    {
                                                                            Icon = Icon.TableEdit,
                                                                            CommandName = "EditParentMaterial",
                                                                            Text = "Sửa"
                                                                    })
                                                      )
                                                      .DirectEvents(de =>
                                                                    {
                                                                        de.Command.EventMask.ShowMask = true;
                                                                        de.Command.ExtraParams.Add(new Parameter("containerId",
                                                                                "wdModifyChild"));
                                                                        de.Command.ExtraParams.Add(new Parameter("command",
                                                                                "command",
                                                                                ParameterMode.Raw));
                                                                        de.Command.ExtraParams.Add(new Parameter("parentStyleId",
                                                                                "record.data.ParentStyleId",
                                                                                ParameterMode.Raw));
                                                                        de.Command.ExtraParams.Add(new Parameter("ParentMaterialId",
                                                                                "record.data.ParentMaterialId",
                                                                                ParameterMode.Raw));
                                                                        de.Command.ExtraParams.Add(new Parameter("childStyleId",
                                                                                Model.Item1 + "",
                                                                                ParameterMode.Raw));
                                                                        de.Command.Url = Url.Action("ParentMaterialCommand");
                                                                        de.AutoDataBind = true;
                                                                    })
                                                      );

                                              column.Add(Html.X()
                                                     .CommandColumn()
                                                     .MinWidth(65)
                                                     .MaxWidth(65)
                                                      .PaddingSpec("0 10")
                                                     .Commands(v =>
                                                             v.Add(new GridCommand
                                                             {
                                                                 Icon = Icon.Delete,
                                                                 CommandName = "DeleteParentMaterial",
                                                                 Text = "Xóa"
                                                             })
                                                     )
                                                     .DirectEvents(de =>
                                                     {
                                                         de.Command.EventMask.ShowMask = true;
                                                         de.Command.ExtraParams.Add(new Parameter("containerId",
                                                                 "wdModifyChild"));
                                                         de.Command.ExtraParams.Add(new Parameter("command",
                                                                 "command",
                                                                 ParameterMode.Raw));
                                                         de.Command.ExtraParams.Add(new Parameter("parentStyleId",
                                                                 "record.data.ParentStyleId",
                                                                 ParameterMode.Raw));
                                                         de.Command.ExtraParams.Add(new Parameter("ParentMaterialId",
                                                                 "record.data.ParentMaterialId",
                                                                 ParameterMode.Raw));
                                                         de.Command.ExtraParams.Add(new Parameter("childStyleId",
                                                                 Model.Item1 + "",
                                                                 ParameterMode.Raw));
                                                         de.Command.Url = Url.Action("ParentMaterialCommand");
                                                         de.Command.Confirmation.ConfirmRequest = true;
                                                         de.Command.Confirmation.BeforeConfirm = "config.confirmation.title = 'Thông báo'; config.confirmation.message = 'Bạn có muốn xóa dòng này không?';";
                                                         de.AutoDataBind = true;
                                                     })
                                                     );
                                              
                                              
                                          })
                             .BottomBar(Html.X()
                                     .PagingToolbar())
                             .Store(Html.X()
                                     .Store()
                                     .RemotePaging(true)
                                     .PageSize(30)
                                     .ID("storeGvChildData")
                                     .AutoLoad(true)
                                     .AutoSync(false)
                                     .Model(c => c.Add(Html.X()
                                             .Model()
                                             .Fields("ParentStyleId",
                                                     "ParentStyleName",
                                                     "ParentMaterialId",
                                                     "ParentMaterialName",
                                                     "Image",
                                                     "Price"
                                             )
                                             .IDProperty("ParentMaterialId")))
                                     .Proxy(c => c.Add(Html.X()
                                             .AjaxProxy()
                                             .Json(true)
                                             .Url(Url.Action("GetParentMaterials"))
                                             .ActionMethods(v => v.Read = HttpMethod.POST)
                                             .Reader(Html.X()
                                                     .JsonReader()
                                                     .Root("data")
                                                     .TotalProperty("total"))
                                             .ExtraParams(param => param.Add(new Parameter("styleId",
                                                     Model.Item1 + "",
                                                     ParameterMode.Value)))
                                             )))
                             );
                 }))


@(Html.X()
          .Window()
          .ID("wdModifyChild")
          .Hidden(true)
          .Modal(true)
          .Resizable(false)
          .Title("Thông tin mẫu - chất liệu (Cha)")
          .Width(550)
          .Height(260)
          .Constrain(true)
          .StyleHtmlCls("background-color:white;")
          )